/*
 * 类名称:ClientEnterpriseController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-09-25 19:51:14        hww     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.annotation.SysLog;
import com.platform.entity.FireExtinguisherEntity;
import com.platform.utils.PageUtils;
import com.platform.utils.R;
import com.platform.controller.AbstractController;
import com.platform.entity.ClientEnterpriseEntity;
import com.platform.service.ClientEnterpriseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 购买企业Controller
 *
 * @author hww
 * @date 2019-09-25 19:51:14
 */
@RestController
@RequestMapping("fs/cliententerprise")
public class ClientEnterpriseController extends AbstractController {
    @Autowired
    private ClientEnterpriseService clientEnterpriseService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("cliententerprise:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<ClientEnterpriseEntity> list = clientEnterpriseService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询购买企业
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("cliententerprise:list")
    public R list(@RequestParam Map<String, Object> params) {
//        Page page = clientEnterpriseService.queryPage(params);
//        return R.ok().put("page", page);
        Page page = clientEnterpriseService.queryPage(params);
        List<ClientEnterpriseEntity> list = page.getRecords();
        PageUtils pageUtil = new PageUtils(list,(int)page.getTotal(),(int)page.getSize(),(int)page.getCurrent());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("cliententerprise:info")
    public R info(@PathVariable("id") String id) {
        ClientEnterpriseEntity clientEnterprise = clientEnterpriseService.getById(id);

        return R.ok().put("clientEnterprise", clientEnterprise);
    }

    /**
     * 新增购买企业
     *
     * @param clientEnterprise clientEnterprise
     * @return R
     */
    @SysLog("新增购买企业")
    @RequestMapping("/save")
    @RequiresPermissions("cliententerprise:save")
    public R save(@RequestBody ClientEnterpriseEntity clientEnterprise) {

        clientEnterpriseService.add(clientEnterprise);

        return R.ok();
    }

    /**
     * 修改购买企业
     *
     * @param clientEnterprise clientEnterprise
     * @return R
     */
    @SysLog("修改购买企业")
    @RequestMapping("/update")
    @RequiresPermissions("cliententerprise:update")
    public R update(@RequestBody ClientEnterpriseEntity clientEnterprise) {

        clientEnterpriseService.update(clientEnterprise);

        return R.ok();
    }

    /**
     * 根据主键删除购买企业
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除购买企业")
    @RequestMapping("/delete")
    @RequiresPermissions("cliententerprise:delete")
    public R delete(@RequestBody String[] ids) {
        clientEnterpriseService.deleteBatch(ids);

        return R.ok();
    }
}
